package flywight;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class BOXFactory {

    private static Map<String, AbstractBox> map ;

    public BOXFactory() {
        map = new HashMap<String, AbstractBox>();
        map.put("I", new IBOx());
        map.put("L", new LBOX());
        map.put("O", new OBOX());
    }

    // 理论上的懒加载，但实际上都会在初始化加载。相对于双检锁来说，双检锁支持懒加载，而内部静态最终类的形式更常用。
    private static final class InstanceHolder {
        static final BOXFactory instance = new BOXFactory();
    }

    // 获取BOX工厂类
    public static BOXFactory createBOXFactory(){
        return InstanceHolder.instance;
    }

    public AbstractBox getBOX(String name){
        return map.get(name);
    }

}
